package 冒泡排序;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @author : ZhuQi
 * @version : 时间:2022/8/11 11:32 版本:
 * 冒泡排序
 */
public class Demo {
    private static int[] array;

    /**
     * 初始化 数组
     */
    @BeforeEach
    public void beforeAll() {
        array = new int[]{1, 3, 5, 7, 9, 10, 8, 6, 4, 2, 0};
    }

    /**
     * 测试内容: 冒泡排序
     */
    @Test
    public void test01() throws Exception {
        for (int i = 0; i < array.length; i++) {
            for (int j = array.length - 1; j > i; j--) {
                int temp;
                if (array[i] > array[j]) {
                    temp = array[j];
                    array[j] = array[i];
                    array[i] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(array));
    }

    /**
     *
     */
    @Test
    public void test02() throws Exception {
        for (int i = 0; i < array.length; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] > array[j]) {
                    int temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(array));
    }







}
